package org.jimmy.tang.lang;

/**
 * @author jimmy
 * 
 */
public class ClassAndTypeCastDemo {
    public static void main(String... arg) {
        testPrimitiveType();
        testAutoTypeCast();
    }

    static void testAutoTypeCast() {
        ClassAndTypeCastDemo test = new ClassAndTypeCastDemo();
        test.med(10, 10);// 2
        test.med(10, (float) 10);// 3
        test.med((float) 10, 10);// 1
    }

    public void med(float a, long b) {
        System.out.println("1");
    }

    public void med(long a, long b) {
        System.out.println("2");
    }

    public void med(long a, float b) {
        System.out.println("3");
    }

    static void testPrimitiveType() {
        int i = 2000;
        float f = 200f;
        double d = i + f;
        System.out.println(d);

        byte a = 10;
        byte b = 90;
        // byte c = a + b;//Type mismatch: cannot convert from int to byte
        int c = a + b;
        System.out.println(c);

        // int e = 2147483648;//The literal 2147483648 of type int is out of

        double x = -9.99;
        int y = (int) x;// -9，直接砍掉小数
        int z = (int) Math.round(x);// -10，得到的是最接近的整数
        System.out.println(y);
        System.out.println(z);
    }
}
